//
//  CustomTableViewCell.m
//  10-UITableViewCell自定义
//
//  Created by 402030900@qq.com on 16/7/27.
//  Copyright © 2016年 402030900@qq.com. All rights reserved.
//

#import "CustomTableViewCell.h"
// 使用@class声明的类,需要在.m中去import
#import "NewsObject.h"
@interface CustomTableViewCell()
@property(nonatomic,strong)UIView * customView;
@property(nonatomic,strong)UIImageView * leftImageView;
@property(nonatomic,strong)UILabel * upLabel;
@property(nonatomic,strong)UILabel * belowLabel;
@property(nonatomic,strong)UILabel * smallLabel;

@end
@implementation CustomTableViewCell
// 1.自定义tableViewCell的初始化方法
// initWithStyle: reuseIdentifier
// 注意: 不要使用initWithFrame
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // tableViewCell默认大小 宽320 高44
        // 初始化时 cell的frame是初始值 不能为自定义视图布局
        NSLog(@"初始化时%@",NSStringFromCGRect(self.frame));
        // 添加子view
        _customView = [[UIView alloc]initWithFrame:CGRectZero];
        _customView.backgroundColor = [UIColor clearColor];
        [self addSubview:_customView];
        // 初始化方法中只负责创建
        // 3. 创建的子视图所添加在哪个父视图上
        // contentView显示内容
        [self.contentView addSubview:_customView];
        
        _leftImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"died"]];

        _upLabel = [[UILabel alloc]init];
        _upLabel.layer.borderWidth = 1;
        _upLabel.text = @"upLabel";
        _belowLabel = [[UILabel alloc]init];
        _belowLabel.layer.borderWidth = 1;
        _belowLabel.text = @"belowLabel";
        _smallLabel = [[UILabel alloc]init];
        _smallLabel.layer.borderWidth = 1;
        _smallLabel.text = @"smallLabel";
        [self.contentView addSubview:_leftImageView];
        [self.contentView addSubview:_upLabel];
        [self.contentView addSubview:_belowLabel];
        [self.contentView addSubview:_smallLabel];
        
        
    }
    return self;
}
// 2.布局子视图及它本身
// 有内容/坐标改变时,会触发该方法
// 注意,判断_smallLabel 的父视图是不是_belowLabel
// [_belowLabel addSubview:_smallLabel];
-(void)layoutSubviews{
    // 千万不要忘记super layoutSubViews
    [super layoutSubviews];
 NSLog(@"%s时,cellframe是%@",__FUNCTION__,NSStringFromCGRect(self.frame));
    
    // layoutSubViews中,负责给视图布局
    // 不要使用cell的frame去进行视图的布局
    // 使用contentView的frame进行布局
    _customView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, 100);
    _leftImageView.frame = CGRectMake(10, 10, 80, 180);
    _upLabel.frame = CGRectMake(100, 10, 265, 80);
    _belowLabel.frame = CGRectMake(100, 110, 265, 80);
    _smallLabel.frame = CGRectMake(275, 150, 80, 30);

    // self.contentView.lyr_height - 10
    
    
}
-(void)setNewsObject:(NewsObject *)newsObject{
    _newsObject = newsObject;

        _leftImageView.image = [UIImage imageNamed:newsObject.newsImage];
        _upLabel.text = newsObject.newsTitle;

}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
